//
//  StudyTCell.m
//  students
//
//  Created by 任辰东 on 2024/2/23.
//

#import "StudyTCell.h"
#import "NSString+timeStamp.h"

@interface StudyTCell ()

@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UIImageView *videoImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *userLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *statusLabel;
@end

@implementation StudyTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)configCellWithModel:(StudyModel *)model
{
    self.titleLabel.text = model.title;
    self.userLabel.text = [NSString stringWithFormat:@"发布人 : %@",model.user_name];
    self.timeLabel.text = [model.create_time dateStringWithFormat:@"yyyy-MM-dd"];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_url]];
    
    //1文章2视频
    if (model.type_id.integerValue == 1) {
        self.videoImageView.hidden = YES;
    }else{
        self.videoImageView.hidden = NO;
    }
    
//    //0未学习1已学习
//    if (model.status.integerValue == 0) {
//        self.statusLabel.text = @"未学习";
//        self.statusLabel.textColor = UIColorFromHex(kColorMain);
//    }else{
//        self.statusLabel.text = @"已学习";
//        self.statusLabel.textColor = UIColorFromHex(kColorPlaceholder);
//    }
}

-(void)setupViews
{
    self.contentView.backgroundColor = UIColorFromHex(kColorBG);
    [self.contentView addSubview:self.containerView];
    [self.containerView addSubview:self.iconImageView];
    [self.containerView addSubview:self.videoImageView];
    [self.containerView addSubview:self.titleLabel];
    [self.containerView addSubview:self.userLabel];
    [self.containerView addSubview:self.timeLabel];
    [self.containerView addSubview:self.statusLabel];
}

-(void)setupLayout
{
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.containerView).offset(15);
        make.left.equalTo(self.containerView).offset(15);
        make.width.mas_equalTo((kScreenWidth-15*2)/3);
        make.height.mas_equalTo((kScreenWidth-15*2)/3*3/4);
        make.bottom.equalTo(self.containerView).offset(-15);
    }];
    
    [self.videoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(self.iconImageView);
        make.height.width.mas_equalTo(30);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.containerView).offset(15);
        make.left.equalTo(self.iconImageView.mas_right).offset(10);
        make.right.equalTo(self.containerView).offset(-15);
    }];
    
    [self.userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(self.iconImageView.mas_centerY).offset(0);
        make.left.equalTo(self.iconImageView.mas_right).offset(10);
        make.right.equalTo(self.containerView).offset(-15);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(self.iconImageView.mas_bottom).offset(0);
        make.left.equalTo(self.iconImageView.mas_right).offset(10);
        make.right.equalTo(self.statusLabel.mas_left).offset(-5);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(self.iconImageView.mas_bottom).offset(0);
        make.right.equalTo(self.containerView).offset(-15);
    }];

}

#pragma mark -- lazyload

-(UIView *)containerView
{
    if (!_containerView) {
        _containerView = [UIView new];
        _containerView.backgroundColor = UIColorFromHex(kColorWhite);
        [_containerView addBottomLineWithEdge:UIEdgeInsetsMake(0, 15, 0, 15)];
    }
    return _containerView;
}

-(UIImageView *)iconImageView
{
    if (!_iconImageView) {
        _iconImageView = [UIImageView new];
        _iconImageView.backgroundColor = [UIColor lightGrayColor];
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}

-(UIImageView *)videoImageView
{
    if (!_videoImageView) {
        _videoImageView = [UIImageView new];
        _videoImageView.image = UIImageWithName(@"video_play");
        _videoImageView.contentMode = UIViewContentModeScaleAspectFill;
        _videoImageView.clipsToBounds = YES;
    }
    return _videoImageView;
}

-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = UIColorFromHex(kColorTitle);
        _titleLabel.font = UIFontSize(17);
    }
    return _titleLabel;
}

-(UILabel *)userLabel
{
    if (!_userLabel) {
        _userLabel = [UILabel new];
        _userLabel.textColor = UIColorFromHex(kColorSubTitle);
        _userLabel.font = UIFontSize(17);
    }
    return _userLabel;
}

-(UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = [UILabel new];
        _timeLabel.textColor = UIColorFromHex(kColorPlaceholder);
        _timeLabel.font = UIFontSize(15);
    }
    return _timeLabel;
}

-(UILabel *)statusLabel
{
    if (!_statusLabel) {
        _statusLabel = [UILabel new];
        _statusLabel.textColor = UIColorFromHex(kColorPlaceholder);
        _statusLabel.font = UIFontSize(15);
        _statusLabel.textAlignment = NSTextAlignmentRight;
    }
    return _statusLabel;
}

@end
